package ServiceTest;

import junit.framework.TestCase;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.kaishengit.pojo.User;
import com.kaishengit.service.UserService;
import com.kaishengit.util.DateUtil;

public class UserServiceTest extends TestCase {
	private UserService userService;
	
	public void setUp(){
		ApplicationContext cxt = new ClassPathXmlApplicationContext("applicationContext.xml");
		userService = (UserService) cxt.getBean("userService");
	}
	
	public void testSave(){
		User user = new User();
		user.setIsenable(true);
		user.setUsername("Jim");
		user.setUserpwd("123");
		user.setCreatetime(DateUtil.getNow());
		user.setRole(1);
		userService.save(user);
	}
	
	public void testsave(){
		User user = new User();
		user.setId(2);
		user.setIsenable(false);
		user.setUsername("Jim");
		user.setUserpwd("123");
		user.setCreatetime(DateUtil.getNow());
		user.setRole(1);
		userService.save(user);
	}
	
	public void testdelete(){
		User user = new User();
		userService.deleteById(3);
	}
	
	public void testdelete2(){
		User user = new User();
		user.setId(2);
		userService.deleteByObject(user);
	}
	
	public void testlogin(){
		String username = "tom";
		String userpwd = "123";
		User user = userService.findByProperties(username, userpwd);
		assertNotNull(user);
	}
}
